//
//  XTStatus.swift
//  Weibo(Swift)
//
//  Created by 肖霆 on 16/5/13.
//  Copyright © 2016年 肖霆. All rights reserved.
//

import UIKit

//微博的数据模型
class XTStatus: NSObject {
    
    //发送这条微博的时间
    var created_at:String?
    //微博的ID
    var id:Int64 = 0 //********************int类型在使用时一定要用 ＝ 0来赋初值，不能使用？，要不然后面就回一直为0！！！！！！！！！！
    
    //微博信息内容
    var text:String?
    //微博来源
    var source:String?
    //用户模型
    var user:XTUser?
    
    //转发微博模型
    var retweeted_status:XTStatus?
    //转发数
    var reposts_count:Int = 0
    //评论数
    var comments_count:Int = 0
    //点赞数
    var attitudes_count:Int = 0
    //配图数据
    var pic_urls:[XTStatusPictureInfo]? //数组
    
    //kvc构造函数
    init(dic:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user"{
        
            guard let dic = value as? [String:AnyObject] else{
                return
            }
            user = XTUser(dic: dic)
        
            
        }else if key == "retweeted_status"{
            guard let dic = value as? [String:AnyObject] else{
                return
            }
            
            retweeted_status = XTStatus(dic: dic)
        }else if key == "pic_urls"{
            guard let dicArray = value as? [[String:AnyObject]] else{
                return
            }
            
            //创建一个空的数组
            var tempArray = [XTStatusPictureInfo]()
            for dic in dicArray{
                let picInfo = XTStatusPictureInfo(dic: dic)

                tempArray.append(picInfo)
            }
            pic_urls = tempArray
            
        }else{
        super.setValue(value, forKey: key)
        }
        
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
